<!doctype html>
<html lang="en">
<head>
    @include('web.layout.head')
    <link rel="stylesheet" href="{{asset('/css/web/user/ebao.css')}}">
</head>
<body>
@include('web.layout.header')
@include('web.layout.user_tab')
<div class="base_member_content">
    <div class="w1200">
        @include('web.layout.seller_nav')
        <div class="nav_right flr">
            <div class="base_content">
                <div class="line_title">收款帐号</div>
                <div class="account_num">
                   我的收款帐号，用于开设店铺交易收款。<font>（仅支持对公帐号）</font>
                   <span>@if(isset($page['total']) && $page['total']) {{$page['total']}} 个 @endif</span>
                </div>
                <div class="table">
                    <table>
                        <thead>
                        <tr>
                            <th width="150" class="text-left">电子ID</th>
                            <th width="150" class="text-left">收款帐号</th>
                            <th width="90">类型</th>
                            <th width="90">状态</th>
                            <th width="100">操作</th>
                            <th width="100"></th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($list as $account)
                            <tr>
                                <td class="text-left">
                                    <div class="dzid"> {{$account['account_id']}}</div>
                                </td>
                                <td class="text-left">
                                    <img class="" src="{{$account['account_icon']}}">
                                    <p>
                                        {{substr($account['bank_no'],0,4)}}  ****  ****  {{substr($account['bank_no'],-4)}}
                                    </p>
                                </td>
                                <td>@if($account['account_type']==1) 对公帐号 @endif</td>
                                <td>@if($account['accout_status']==0) 未开通 @else 已开通 @endif</td>
                                <td>
                                          @if($account['accout_status']==1 &&  $account['is_default']==0)
                                          <a data-id="{{$account['id']}}" class="setup">设为默认</a>
                                          @endif
                                            @if($account['accout_status']==1  )
                                          <a data-id="{{$account['id']}}" data-id="{{$account['id']}}"   data-bank_no="{{$account['bank_no']}}"   data-account_name="{{$account['account_name']}}"  data-cert_no="{{$account['cert_no']}}"   data-bank_phone="{{$account['bank_phone']}}"   class="list_account">查看</a>
                                          @endif
                                          @if($account['accout_status']== 0)<a data-id="{{$account['id']}}" data-bank_name="{{$account['bank_name']}}"   data-cert_no="{{$account['cert_no']}}"  data-account_name="{{$account['account_name']}}"   data-bank_no="{{$account['bank_no']}}" data-bank_phone="{{$account['bank_phone']}}" class="add_account">绑定</a>@endif
                                </td>
                                <td>
                                @if($account['is_default']==1) <div class="default_option">默认收款</div> @endif
                                    
                                </td>
                            </tr>
                             @endforeach
                           
                        </tbody>
                    </table>
                </div>
                <!-- <div class="add_account">+添加收款帐号</div> -->
            </div>
        </div>
    </div>
</div>
<div class="bg_h"></div>
<div class="account_box add_account_box">
    <div class="h_top"><h2>收款帐号管理 </h2><a class="close_box">×</a></div>
     <div class="fl shu_box">
        <span>账户名称</span>
        <input type="text" name="account_name" class="account_name"  >
        <p class="jm_error"></p>
    </div>
    <div class="fl shu_box">
        <span>银行帐号</span>
        <input type="text" name="bank_no1" class="bank_no1" readonly="readonly" >
        <input type="hidden" name="bank_no" class="bank_no" value="" >
        <p class="jm_error"></p>
    </div>
      <div class="fl shu_box">
        <span>身份证号</span>
        <input type="text" name="cert_no" class="cert_no"  >
        <p class="jm_error"></p>
    </div>
    
    <div class="fl shu_box">
        <span>银行类型</span>
        <font>对公支付</font>
        <p class="jm_error"></p>
    </div>
      <div class="fl shu_box">
        <span>地区</span>
         <select id="bank_province"><option value="-1">请选择省</option></select>
        <select id="bank_city"><option value="-1">请选择市</option></select>
    </div>
     <div class="fl shu_box">
        <span>开户行联行号</span>
         <select id="bank_list" name="bank_list" class="bank_list"><option value="-1">请选择银行</option></select>
         <p class="jm_error"></p>
    </div>
    <div class="fl shu_box">
        <span>预留手机号</span>
        <input type="text" name="bank_phone" class="bank_phone"  >
        <p class="jm_error"></p>
    </div>
    <div class="fl shu_box">
        <span>验证码</span>
        <input type="text" name="bank_code" class="bank_code" autocomplete="off">
        <p class="jm_error"></p>
        <a href="javascript:;" id='send_code' class="js-code">发送</a>
        <div class="fl" id="codetime"></div>
    </div>
    <div class="fl shu_box">
        <span>商城支付密码</span>
        <input type="password" name="pay_password" class="pay_password" autocomplete="off" >
        <p class="jm_error"></p>
    </div>
    <div class="btn_box">
    <input type="hidden" name="mobileSerial" value=""  id="mobileSerial"/>
    <input type="hidden" name="bname" class="bname" value=""  id="bname"/>
        <div class="btn_cancel close_box">取消</div>
        <div class="btn_confirm add_btn" data-id="1" >确定</div>
    </div>
</div>

<div class="account_box list_account_box">
    <div class="h_top"><h2>收款帐号管理</h2><a class="close_list_box">×</a></div>
     <div class="fl shu_box">
        <span>账户名称</span>
        <input type="text" name="account_name" class="account_name"  >
    </div>
    <div class="fl shu_box">
        <span>银行帐号</span>
        <input type="text" name="bank_no" class="bank_no"  readonly="readonly">
    </div>
      <div class="fl shu_box">
        <span>身份证号</span>
        <input type="text" name="cert_no" class="cert_no"   readonly="readonly">
    </div>
    
    <div class="fl shu_box">
        <span>银行类型</span>
        <font>对公支付</font>
    </div>
  
    <div class="fl shu_box">
        <span>预留手机号</span>
        <input type="text" name="bank_phone" class="bank_phone"   readonly="readonly">
    </div>
    
    <div class="btn_box">
        <div class="btn_cancel close_list_box">关闭</div>
    </div>
</div>

@include('web.layout.footer')
<script src="{{asset('/js/czbank.js')}}"></script>
<script type="text/javascript">
    $(function(){
      //设为默认
      $('.setup').click(function(){
          var id = $(this).attr('data-id');
          layer.confirm('确定设为默认收款？', {
              btn: ['确定', '取消'] //可以无限个按钮
          }, function (index) {
              $.ajax({
                  url: "/member/seller/account/update_default",
                  type: 'post',
                  dataType: 'json',
                  data: {'id': id,'is_default':1},
                  success: function (data) {
                      if (0 == data.code) {
                          layer.alert("设置成功", {
                              icon: 1
                          }, function () {
                              location.reload();
                          });
                      } else {
                          layer.alert(data.message, {
                              icon: 2
                          });
                      }
                  }
              });
          }, function (index, layero) {
              layer.close(index);
          });
      });
// 	$(".bank_no").change(function(){
// 		$.ajax({
//             url: "/member/seller/checkcard",
//             type: 'get',
//             dataType: 'json',
//             data: {'bank_no': $(this).val()},
//             success: function (data) {
//                 if (0 == data.code) {
//                     $("#bname").val(data.message);
//                     $(".bank_no").parent().find('.jm_error').hide();
//                 } else {
//                 	$(".bank_no").parent().find('.jm_error').show();
//                 	$(".bank_no").parent().find('.jm_error').html('银行帐号错误');
//                 }
//             }
//         });
// 	});

	$("#bank_city").change(function(){
		var bank = czbank.bankList;
		var bname = $("#bname").val();
		var bankType="";
		for(b in bank){
			//if(bank[b].bankName==bname){
			if(bank[b].bankName.indexOf(bname) != -1 || bname.indexOf(bank[b].bankName) != -1 ){
				bname = bank[b].bankName;
				bankType = bank[b].bankType;
				break;
			} 
		}
		if(bankType == ""){
			for(b in bank){
				if(bname.indexOf("农村合作银行") != -1 ){
					bankType = 317;
					break;
				}else if(bname.indexOf("村镇银行") != -1 ){
					bankType = 320;
					break;
				}else if(bname.indexOf("农村商业银行") != -1 && bname.indexOf("上海农村商业银行") == -1 ){
					bankType = 314;
					break;
				}else if(bname.indexOf("城市信用") != -1 ){
					bankType = 401;
					break;
				}else if(bname.indexOf("农村信用") != -1 ){
					bankType = 402;
					break;
				}else{
					bankType = 313;//城市商业银行
					break;
				} 
			}
		}
		
	 
		if(bankType && bname){
			$.ajax({
          	  url: '/member/seller/getbankcode',
                type: 'get',
                dataType: 'json',
                data: {'bankType': bankType,'branchName':bname,'cityCode':$(this).val()},
                success: function (data) {
                    if (0 == data.code) {
                        var bl = data.data.branchList;
                        var str = "<option value='-1'>请选择银行</option>";
                        for(b in bl){
                            str +="<option value='"+bl[b].branchNo+"'>"+bl[b].branchName+"</option>";
                        }
                        $("#bank_list").html(str);
                    }  
                }
            });
		}
	});
      //删除
      $('.del').click(function(){
          var id = $(this).attr('data-id');
          layer.confirm('确定删除？', {
              btn: ['确定', '取消'] //可以无限个按钮
          }, function (index) {
              $.ajax({
            	  url: '{{Request::url()}}/'+id,
                  type: 'delete',
                  dataType: 'json',
                  data: {'id': id},
                  success: function (data) {
                      if (0 == data.code) {
                          layer.alert("删除成功", {
                              icon: 1
                          }, function () {
                              location.reload();
                          });
                      } else {
                          layer.alert(data.message, {
                              icon: 2
                          });
                      }
                  }
              });
          }, function (index, layero) {
              layer.close(index);
          });
      });
      var eidt_id;//用于判断添加还修改
      $('.add_account').click(function(){
    	  eidt_id = $(this).attr('data-id');
    	 $('.account_name').val($(this).attr("data-account_name"));
    	 $('.bank_no1').val($(this).attr("data-bank_no"));
    	 $('.bank_no').val($(this).attr("data-bank_no"));
    	 $('.bname').val($(this).attr("data-bank_name"));
    	 $(".bank_no").change();
          var al = czbank.provinceList;
          var str = "<option value='-1'>请选择省</option>";
          for(a in al){
              str +="<option value='"+a+"'>"+al[a].provinceName+"</option>";
          }
         
          $("#bank_province").html(str);
            $('.bg_h').show();
            $('.add_account_box').show();
            setTimeout(function(){
                $('.bank_code').val('');
                $('.pay_password').val('');
            },100);
      });

      $('.list_account').click(function(){
    	  eidt_id = $(this).attr('data-id');
    	 $('.account_name').val($(this).attr("data-account_name"));
    	 $('.bank_no1').val($(this).attr("data-bank_no"));
    	 $('.bank_no').val($(this).attr("data-bank_no"));
    	 $('.cert_no').val($(this).attr("data-cert_no"));
    	 $('.bank_phone').val($(this).attr("data-bank_phone"));
    	 $(".bank_no").change();
      
         
            $('.bg_h').show();
            $('.list_account_box').show();
         
      });

      $("#bank_province").change(function(){
    	  var str = "<option value='-1'>请选择市</option>";
    	  var cl = czbank.provinceList[$(this).val()].cityList;
          for(c in cl){
              str +="<option value='"+cl[c].cityCode+"'>"+cl[c].cityName+"</option>";
          }
          $("#bank_city").html(str);
      });
      $('.close_box').click(function(){
    	 	$('.account_name').val('');
            $('.bank_no').val('');
            $('.bank_phone').val('');
            $('.bank_list').val(-1);
            $('.bank_code').val('');
            $('.pay_password').val('');
            $('.cert_no').val('');
            $('.bg_h').hide();
            $('.add_account_box').hide();
      });

      $('.close_list_box').click(function(){
  	 	$('.account_name').val('');
          $('.bank_no').val('');
          $('.bank_phone').val('');
          $('.bank_list').val(-1);
          $('.bank_code').val('');
          $('.pay_password').val('');
          $('.cert_no').val('');
          $('.bg_h').hide();
          $('.list_account_box').hide();
    });
      var myDate = new Date();
      var newTime = myDate.getTime();
        var timePoor = $.cookie("endtime") - newTime;

        if(timePoor < 0){
            $.cookie("endtime",null); //使cookie失效
        }
        var maxtime;
        maxtime = parseInt(timePoor/1000);
        var time;
        if(maxtime > 0){
            $(".js-code").hide();
            $("#codetime").show();
            time = setInterval(Count,1000);
        }
        function Count(){
            if(maxtime>=0){
                $(".js-code").hide();
                $("#codetime").show();
                var seconds = Math.floor(maxtime%60);
                var msg = seconds+"秒";
                $("#codetime").html(msg);
                --maxtime;
            }else{
                clearInterval(time);
                $(".js-code").show();
                $("#codetime").hide();
            }
        }
      //企业注册
        $('.js-code').click(function () {
            $('.jm_error').html('');
            var isPhone=/^1[0-9]{10}$/;//手机号码验证
            var phone = $(".bank_phone");
            if (phone.val() == '') {
                phone.parent().find('.jm_error').html('请输入手机号码');
                return false;
            }
            if (!isPhone.test(phone.val())) {
                phone.parent().find('.jm_error').html('手机号码格式不正确');
                return false;
            }
 
            $.ajax({
            	url: '/member/seller/account/sendsms',
                type: 'POST',
                dataType: 'json',
                data: {mobileMark:phone.val()},
                success:function (data) {
                    if (data.code == 0) {
                        var mytime = myDate.getTime(); //获取当前时间戳
                        var endtime = mytime+1000*60; //计算结束时间戳
                        $.cookie("endtime",endtime,{expires:endtime});
                        maxtime = 59;
                        time = setInterval(Count,1000);
                        $(".js-code").hide();
                        $("#mobileSerial").val(data.mobileSerial);
                        $("#codetime").html('60秒').show();
                        layer.alert('短信已发放，请注意查收',{icon: 1});
                    }else{
                        layer.alert(data.message,{
                            icon: 2
                        });
                    };
                }
            })
        })
      //添加
      $('.add_btn').click(function(){
          
            $('.jm_error').html('');
            var isPhone=/^1[0-9]{10}$/;//手机号码验证

            var account_name = $(".account_name");
            if (account_name.val() == '') {
            	account_name.parent().find('.jm_error').html('请输入开户名');
                return false;
            }

            var bank_list = $(".bank_list");
            if (bank_list.val() == -1) {
            	bank_list.parent().find('.jm_error').html('请选中开户行联行号');
                return false;
            }
            
            var bank_no = $(".bank_no");
            if (bank_no.val() == '') {
                bank_no.parent().find('.jm_error').html('请输入银行帐号');
                return false;
            }
            var phone = $(".bank_phone");
            if (phone.val() == '') {
                phone.parent().find('.jm_error').html('请输入手机号码');
                return false;
            }

            var cert_no = $(".cert_no");
            if (cert_no.val() == '') {
            	cert_no.parent().find('.jm_error').html('请输入身份证号');
                return false;
            }
            
            if (!isPhone.test(phone.val())) {
                phone.parent().find('.jm_error').html('手机号码格式不正确');
                return false;
            }
            var bank_code = $(".bank_code");
            if (bank_code.val() == '') {
                bank_code.parent().find('.jm_error').html('请输入验证码');
                return false;
            }
            var pay_password = $(".pay_password");
            if (pay_password.val() == '') {
                pay_password.parent().find('.jm_error').html('请输入商城支付密码');
                return false;
            }
            $.ajax({
                url: '/member/seller/account',
                type: 'POST',
                dataType: 'json',
                data:{"pay_password":pay_password.val(),"bank_no":bank_no.val(), "bank_phone":phone.val(),"bank_code":bank_code.val(),'rec_account_id':eidt_id,'bank_name':$("#bname").val(),
                    "cert_no":cert_no.val(),'account_name':account_name.val(),"mobileSerial":$("#mobileSerial").val(),"accountBranchNo":bank_list.val()},
                success: function (data) {
                    if (data.code == 0) {
                        layer.alert('绑定成功',{icon: 1});
                        location.reload();
                    } else {
                        layer.alert(data.message, {
                            icon: 0
                        });
                    }
                }

            })
      });
    });

</script>

</body>
</html>